package cn.edu.sgu.www.mhxysy.controller.equipment;

import cn.edu.sgu.www.mhxysy.pager.Pager;
import cn.edu.sgu.www.mhxysy.consts.CustomConstants;
import cn.edu.sgu.www.mhxysy.consts.CustomMessages;
import cn.edu.sgu.www.mhxysy.consts.MimeTypes;
import cn.edu.sgu.www.mhxysy.dto.equipment.ForgeBookCategoryDTO;
import cn.edu.sgu.www.mhxysy.entity.equipment.ForgeBookCategory;
import cn.edu.sgu.www.mhxysy.restful.JsonPage;
import cn.edu.sgu.www.mhxysy.restful.JsonResult;
import cn.edu.sgu.www.mhxysy.service.equipment.ForgeBookCategoryService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 沐雨橙风ιε
 * @version 1.0
 */
@Api(tags = "制造书类型管理")
@ApiSupport(author = CustomConstants.AUTHOR)
@Validated
@RestController
@RequestMapping(path = "/forge_book_category", produces = MimeTypes.APPLICATION_JSON_CHARSET_UTF_8)
public class ForgeBookCategoryController {

    private final ForgeBookCategoryService forgeBookCategoryService;

    @Autowired
    public ForgeBookCategoryController(ForgeBookCategoryService forgeBookCategoryService) {
        this.forgeBookCategoryService = forgeBookCategoryService;
    }

    @ApiOperation("添加装备制造书类型")
    @ApiOperationSupport(ignoreParameters = "id")
    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    public JsonResult<Void> insert(@Validated ForgeBookCategoryDTO forgeBookCategoryDTO) {
        forgeBookCategoryService.insert(forgeBookCategoryDTO);

        return JsonResult.success(CustomMessages.INSERT_SUCCESS);
    }

    @ApiOperation("通过ID修改装备制造书类型")
    @RequestMapping(value = "/updateById", method = RequestMethod.POST)
    public JsonResult<Void> updateById(@Validated ForgeBookCategoryDTO forgeBookCategoryDTO) {
        forgeBookCategoryService.updateById(forgeBookCategoryDTO);

        return JsonResult.success(CustomMessages.UPDATE_SUCCESS);
    }

    @ApiOperation("分页查询装备制造书类型列表")
    @RequestMapping(value = "/selectByPage", method = RequestMethod.GET)
    public JsonResult<JsonPage<ForgeBookCategory>> selectByPage(Pager<ForgeBookCategory> pager) {
        Page<ForgeBookCategory> page = forgeBookCategoryService.selectByPage(pager);

        return JsonResult.restPage(page);
    }

}